package com.gxa.jjty.admin.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.service.RecitalService;
import com.gxa.jjty.core.common.JsonResult;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.pojo.Recital;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author asus
 */
@RestController
@RequestMapping("/recital")
@Api(tags = "评述配置管理")
@Log4j2
public class RecitalController {

    @Autowired
    RecitalService recitalService;

    @PostMapping("/getRecital")
    @ApiOperation("查询评述配置")
    @ApiImplicitParams({
            @ApiImplicitParam (name = "page",value = "页码"),
            @ApiImplicitParam(name = "size",value ="每页的记录数" )
    })
    public Map selectRecital(@RequestParam("page") Integer page,
                             @RequestParam("size") Integer size) throws IllegalAccessException {

        PageInfo<Recital> recitalPageInfo = recitalService.selectByPage(page, size);
        List<Recital> recitalList = recitalPageInfo.getList();
        long total = recitalPageInfo.getTotal();
        HashMap<Object, Object> map = new HashMap<>();
        map.put("RecitalList", recitalList);
        map.put("total",total);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/putRecital")
    @ApiOperation("添加评述配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start",value = "开始的值"),
            @ApiImplicitParam(name = "end",value = "结束的值"),
            @ApiImplicitParam(name = "expression",value = "表现"),
            @ApiImplicitParam(name = "report",value = "报告"),
            @ApiImplicitParam(name = "sort",value = "排序"),
            @ApiImplicitParam(name = "recitalStatus",value = "状态"),
    })
    public Map insertRecital(@RequestBody Recital recital) throws BusinessException {
        recitalService.insertRecital(recital);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData("添加成功");
        return jsonResult.getDataMap();
    }


    @PostMapping("/setRecital")
    @ApiOperation("编辑评述配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start",value = "开始的值"),
            @ApiImplicitParam(name = "end",value = "结束的值"),
            @ApiImplicitParam(name = "expression",value = "表现"),
            @ApiImplicitParam(name = "report",value = "报告"),
            @ApiImplicitParam(name = "sort",value = "排序"),
            @ApiImplicitParam(name = "recital_status",value = "状态"),
            @ApiImplicitParam(name = "id",value = "Id"),
    })
    public  Map updateRecital(@RequestBody Recital recital) throws BusinessException {
        recitalService.updateRecitalService(recital);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData("更新成功");
        return jsonResult.getDataMap();

    }

   @PostMapping("/deleteRecital")
    @ApiOperation("删除评述配置")
    public Map deleteRecital(@RequestParam("id") Long id) throws BusinessException {
        recitalService.deleteById(id);
        JsonResult jsonResult = new JsonResult();
       jsonResult.setCode("1");
       jsonResult.setData("删除成功");
       return jsonResult.getDataMap();
    }


}
